package org.jeecg.modules.website.controller.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.website.entity.WebSchoolImage;
import org.jeecg.modules.website.service.IWebSchoolImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 校园介绍表
 * @Author: jeecg-boot
 * @Date:   2024-08-05
 * @Version: V1.0
 */
@Api(tags="网站API-学校轮播图")
@RestController
@RequestMapping("/api/web/webSchoolImage")
@Slf4j
public class WebSchoolImageApiController extends JeecgController<WebSchoolImage, IWebSchoolImageService> {
    @Autowired
    private IWebSchoolImageService webSchoolImageService;



    @ApiOperation(value="学校轮播图-首页校园新闻轮播", notes="学校信息表-首页校园轮播图")
    @GetMapping(value = "/listImg")
    public Result<IPage<WebSchoolImage>> queryPageListImg(WebSchoolImage  webSchoolImage,
                                                            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                            HttpServletRequest req) {
        pageSize = 5;
        QueryWrapper<WebSchoolImage> queryWrapper = QueryGenerator.initQueryWrapper(webSchoolImage, req.getParameterMap());
        queryWrapper.eq("publish_status",1); // 只查询已发布的
       // queryWrapper.eq("category","sys_school_news"); // 只查询新闻动态
       // queryWrapper.isNotNull("cover_image");
        //queryWrapper.eq("priority","H"); // 优先级高

        queryWrapper.last(" order by sort asc"); // 根据发布时间排序
        queryWrapper.lambda().select(WebSchoolImage.class, i -> !i.getProperty().equals("update_time"));
        Page<WebSchoolImage> page = new Page<WebSchoolImage>(pageNo, pageSize);
        IPage<WebSchoolImage> pageList = webSchoolImageService.page(page, queryWrapper);
        return Result.OK(pageList);
    }


}